#!/home/joshua/.pyenv/versions/anaconda3/bin/python3

"""
写一个程序，实现以下功能：

1. 输出当前时间
2. 输出当前日期
3. 输出当前日期和时间
4. 可以不停地往前走（一秒一秒，一天一天）

"""

from datetime import date, timedelta


class Calendar:

    def __init__(self, year, month, day):
        self.dt = date(year, month, day)

    def advance(self, days=1):
        self.dt += timedelta(days=days)

    def __str__(self):
        return self.dt.strftime('%F')


class Clock:

    def __init__(self, hour, minute, second):
        self.hour = hour
        self.minute = minute
        self.second = second

    def tick(self):
        self.second += 1
        if self.second == 60:
            self.second = 0
            self.minute += 1
        if self.minute == 60:
            self.minute = 0
            self.hour += 1
        if self.hour == 24:
            self.hour = 0

    def __str__(self):
        return '%02d:%02d:%02d' % (self.hour, self.minute, self.second)


class CalendarClock(Calendar, Clock):

    def __init__(self, year, month, day, hour, minute, second):
        Calendar.__init__(self, year, month, day)
        Clock.__init__(self, hour, minute, second)

    def tick(self):
        Clock.tick(self)
        if self.hour == self.minute == self.second == 0:
            Calendar.advance(self)

    def __str__(self):
        return '%s %s' % (Calendar.__str__(self), Clock.__str__(self))


if __name__ == '__main__':
    cal = Calendar(2018, 6, 27)
    print(cal)
    cal.advance()
    print(cal)
    cal.advance(3)
    print(cal)
    cal.advance(-1)
    print(cal)

    time = Clock(11, 2, 1)
    print(time)
    time.tick()
    print(time)

    cc = CalendarClock(2018, 6, 30, 23, 59, 58)
    print(cc)
    cc.tick()
    print(cc)
    cc.tick()
    print(cc)
